/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author kaibiibrahim
 */
@Entity
@Table(name = "commande")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Commande.findAll", query = "SELECT c FROM Commande c"),
    @NamedQuery(name = "Commande.findById", query = "SELECT c FROM Commande c WHERE c.id = :id"),
    @NamedQuery(name = "Commande.findByRef", query = "SELECT c FROM Commande c WHERE c.ref = :ref"),
    @NamedQuery(name = "Commande.findByDateCmd", query = "SELECT c FROM Commande c WHERE c.dateCmd = :dateCmd"),
    @NamedQuery(name = "Commande.findByTotal", query = "SELECT c FROM Commande c WHERE c.total = :total"),
    @NamedQuery(name = "Commande.findBySommePaye", query = "SELECT c FROM Commande c WHERE c.sommePaye = :sommePaye"),
    @NamedQuery(name = "Commande.findByCredit", query = "SELECT c FROM Commande c WHERE c.credit = :credit"),
    @NamedQuery(name = "Commande.findByBenefice", query = "SELECT c FROM Commande c WHERE c.benefice = :benefice"),
    @NamedQuery(name = "Commande.findByIsValid", query = "SELECT c FROM Commande c WHERE c.isValid = :isValid")})
public class Commande implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "ref")
    private String ref;
    @Column(name = "date_cmd")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCmd;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "total")
    private Double total;
    @Column(name = "somme_paye")
    private Double sommePaye;
    @Column(name = "credit")
    private Double credit;
    @Column(name = "benefice")
    private Double benefice;
    @Column(name = "is_valid")
    private String isValid;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "commande")
    private Collection<LignCmd> lignCmdCollection;
    @OneToMany(mappedBy = "cmdId")
    private Collection<ComdCalc> comdCalcCollection;
    @JoinColumn(name = "client_id", referencedColumnName = "id")
    @ManyToOne
    private Client clientId;

    public Commande() {
    }

    public Commande(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getRef() {
        return ref;
    }

    public void setRef(String ref) {
        String oldRef = this.ref;
        this.ref = ref;
        changeSupport.firePropertyChange("ref", oldRef, ref);
    }

    public Date getDateCmd() {
        return dateCmd;
    }

    public void setDateCmd(Date dateCmd) {
        Date oldDateCmd = this.dateCmd;
        this.dateCmd = dateCmd;
        changeSupport.firePropertyChange("dateCmd", oldDateCmd, dateCmd);
    }

    public Double getTotal() {
        return total;
    }

    public void setTotal(Double total) {
        Double oldTotal = this.total;
        this.total = total;
        changeSupport.firePropertyChange("total", oldTotal, total);
    }

    public Double getSommePaye() {
        return sommePaye;
    }

    public void setSommePaye(Double sommePaye) {
        Double oldSommePaye = this.sommePaye;
        this.sommePaye = sommePaye;
        changeSupport.firePropertyChange("sommePaye", oldSommePaye, sommePaye);
    }

    public Double getCredit() {
        return credit;
    }

    public void setCredit(Double credit) {
        Double oldCredit = this.credit;
        this.credit = credit;
        changeSupport.firePropertyChange("credit", oldCredit, credit);
    }

    public Double getBenefice() {
        return benefice;
    }

    public void setBenefice(Double benefice) {
        Double oldBenefice = this.benefice;
        this.benefice = benefice;
        changeSupport.firePropertyChange("benefice", oldBenefice, benefice);
    }

    public String getIsValid() {
        return isValid;
    }

    public void setIsValid(String isValid) {
        String oldIsValid = this.isValid;
        this.isValid = isValid;
        changeSupport.firePropertyChange("isValid", oldIsValid, isValid);
    }

    @XmlTransient
    public Collection<LignCmd> getLignCmdCollection() {
        return lignCmdCollection;
    }

    public void setLignCmdCollection(Collection<LignCmd> lignCmdCollection) {
        this.lignCmdCollection = lignCmdCollection;
    }

    @XmlTransient
    public Collection<ComdCalc> getComdCalcCollection() {
        return comdCalcCollection;
    }

    public void setComdCalcCollection(Collection<ComdCalc> comdCalcCollection) {
        this.comdCalcCollection = comdCalcCollection;
    }

    public Client getClientId() {
        return clientId;
    }

    public void setClientId(Client clientId) {
        Client oldClientId = this.clientId;
        this.clientId = clientId;
        changeSupport.firePropertyChange("clientId", oldClientId, clientId);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commande)) {
            return false;
        }
        Commande other = (Commande) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Commande[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
